<template>
	<view style="background-color: #f6f7f8;">
		<view class="cbg-white u-m-t-15">
			<view class="u-m-l-30 u-m-r-30">
				<view class="u-p-t-15 u-p-b-15" @tap="chooseLocation()" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;font-size: 30rpx;">
							请选择服务地址
						</view>
						<view style="width: 60%;text-align: right;">
							<text style="font-size: 28rpx;"
								:style="{color:(userInfo.location.address===undefined || userInfo.location.address==='')?'#AAAAAA':'#354F60'}">{{(userInfo.location.address===undefined || userInfo.location.address==='')?'选择服务地址(必填) >':userInfo.location.address}}</text>
						</view>
					</view>
				</view>
				<view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;font-size: 30rpx;">
							详细地址
						</view>
						<input v-model="userInfo.detailAddress" style="font-size:28rpx;width: 60%;text-align: right;"
							placeholder="请输入详细地址 门牌号(必填)" placeholder-style="text-align: right;color:#AAAAAA" />
					</view>
				</view>
				<view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;font-size: 30rpx;">
							联系人
						</view>
						<input v-model="userInfo.name" style="font-size:16px;width: 60%;text-align: right;" type="text"
							placeholder="请输入您的姓名" placeholder-style="text-align: right;color:#AAAAAA" />
					</view>
				</view>

				<view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;font-size: 30rpx;">
							电话
						</view>
						<input v-model="userInfo.phone" style="font-size:16px;width: 60%;text-align: right;"
							type="number" placeholder="请输入手机号码" placeholder-style="text-align: right;color:#AAAAAA"
							@input="phoneChange()" maxlength="11" />
					</view>
				</view>

				<!-- <view class="u-p-t-15 u-p-b-15" @click="serveTpe" style="color: #354F60;"
					v-if="orderType!='nanny_service'">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;font-size: 30rpx;">
							请选择{{orderType=='hospital_care' ? '医院':'社区'}}
						</view>
						<view style="width: 60%;text-align: right;">
							<text style="font-size: 28rpx;"
								:style="{color:(serveType===undefined ||serveType==='')?'#AAAAAA':'#354F60'}">{{(serveType===undefined ||serveType==='')?'选择类型(必填) >':serveType}}</text>
						</view>
					</view>
				</view> -->


				<!-- <view class="u-p-t-15 u-p-b-15" @click="showNay = true" style="color: #354F60;"
					v-if="orderType=='nanny_service'">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;font-size: 30rpx;">
							请选择月数
						</view>
						<view style="width: 60%;text-align: right;">
							<text style="font-size: 28rpx;"
								:style="{color:(nannyMonth===undefined ||nannyMonth==='')?'#AAAAAA':'#354F60'}">{{(nannyMonth===undefined ||nannyMonth==='')?'选择服务月数(必填) >':nannyMonth}}个月</text>
						</view>
					</view>
				</view> -->
				<!-- <view class="u-p-t-15 u-p-b-15" @click="Department" style="color: #354F60;"
					v-if="orderType=='hospital_care'">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;font-size: 30rpx;">
							请选择科室
						</view>
						<view style="width: 60%;text-align: right;">
							<text style="font-size: 28rpx;"
								:style="{color:(DepartmentName===undefined ||DepartmentName==='')?'#AAAAAA':'#354F60'}">{{(DepartmentName===undefined ||DepartmentName==='')?'选择类型(必填) >':DepartmentName}}</text>
						</view>
					</view>
				</view> -->
				<!-- <view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;font-size: 30rpx;">
							被护理人名称
						</view>
						<input v-model="becareName" style="font-size:16px;width: 60%;text-align: right;" type="text"
							placeholder="请输入姓名" placeholder-style="text-align: right;color:#AAAAAA" />
					</view>
				</view> -->
				<!-- 	<view class="u-p-t-15 u-p-b-15" style="color: #354F60;" v-if="orderType=='hospital_care'">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;font-size: 30rpx;">
							床号
						</view>
						<input v-model="bedNum" style="font-size:16px;width: 60%;text-align: right;" maxlength="3"
							type="number" placeholder="请输入床号" placeholder-style="text-align: right;color:#AAAAAA" />
					</view>
				</view> -->
				<view class="cbg-white u-m-t-15">
					<view class="u-m-l-30 u-m-r-30"> </view>
				</view>







				<view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;">
							<view>
								<image style="height: 15px;width: 15px; margin-top: 2px;margin-right: 3px;"
									src="../../static/order/jishi.png"></image>
							</view>
							<view style="font-size: 30rpx;">服务人员</view>
						</view>
						<view style="width: 60%;text-align: right;color: #AAAAAA;">
							<view style="float: right;margin-right: 5px;">
								<image style="height: 23px;width: 23px;margin-top: -2px;border-radius:50%;"
									v-if="jishiObj.avatar===''" src="../../static/order/head.png"></image>
								<image style="height: 23px;width: 23px;margin-top: -2px;border-radius:50%;" v-else
									:src="jishiObj.avatar" mode="aspectFill"></image>
							</view>
							<view style="float: right;margin-right: 5px;color: #333333;">{{jishiObj.sex===0?'男':'女'}}
							</view>
							<view style="float: right;margin-right: 5px;color: #333333;">{{jishiObj.name}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>


		<view class=""
			style="padding: 30rpx;padding-top: 10rpx;padding-bottom: 10rpx;background-color: #fff;margin-top: 15rpx;"
			v-if="orderType!='nanny_service'">
			<view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
				<view class="cflex-r u-font-13" style="align-items:center;width: 100%;" @tap="chooseTime()">
					<view class="cflex-r" style="width: 40%;color: #333333;">
						<view>
							<image style="height: 15px;width: 15px; margin-top: 2px;margin-right: 3px;"
								src="../../static/order/shijian.png"></image>
						</view>
						<view style="font-size: 30rpx;">服务时间(必选)</view>
					</view>
					<view style="width: 60%;text-align: right;color: #AAAAAA;">
						<view style="float: right;margin-right: 5px;" v-show="userInfo.yuYueTime===''">
							<span style="font-size: 28rpx;margin-right: 10rpx;">选择时间</span>
							<u-icon name="rewind-right-fill" color="#ff6d18" size="28"></u-icon>
						</view>
					</view>
				</view>
				<view class="" v-if="timeMood">
					<view class="" style="margin-top: 15rpx;" v-for="(item,i) in timeMood">
						<view class="" style="margin-bottom: 10rpx;" v-if="item.show">{{item.day}}
						</view>
						<view class="" style="display: flex;flex-wrap: wrap;">
							<view class="" style="margin-left: 15rpx;margin-top: 10rpx;" v-if="meth.change==true"
								v-for="meth in item.timeList">
								<u-tag :text="meth.startTime + '-'+meth.endTime" closeable
									@close='closetag(meth,item.day)' />
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>









		<view class="cbg-white u-m-t-15">
			<view class="u-m-l-30 u-m-r-30">
				<view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="color: #333333;">
							<image
								style="height: 55px;width: 55px; margin-top: 2px;margin-right: 3px;border-radius: 15rpx;"
								v-show="goodsObj.photo===''" src="../../static/order/spa.png" mode="aspectFill"></image>
							<image
								style="height: 55px;width: 55px; margin-top: 2px;margin-right: 3px;border-radius: 15rpx;"
								v-show="goodsObj.photo!==''" :src="goodsObj.photo" mode="aspectFill"></image>
						</view>
						<view style="margin-left: 10px;text-align: left;color: #AAAAAA;">
							<view style="margin-right: 5px;color: #333333;font-size: 15px;font-weight: bold;">
								{{goodsObj.name}}
							</view>
							<view
								style="margin-right:5px;color:#FF5400;font-size:15px;font-weight:bold;margin-top: 7px;">
								￥{{goodsObj.finalPrice}}</view>
						</view>
					</view>
				</view>

			</view>
		</view>


		<view class="cbg-white u-m-t-15">
			<view class="u-m-l-30 u-m-r-30">
				<view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;">
							<view style="font-size: 28rpx;">出行方式</view>
						</view>
						<view style="width: 60%;text-align: right;color: #AAAAAA;">
							<view :class="{'travel1':travalMode==3 || travalMode==2,'travel2':travalMode==1}"
								style=" float: right;padding:3px;border-radius: 3px;" @tap="changeTraval()">出租/滴滴</view>
							<view :class="{'travel3':travalMode==3,'travel1':travalMode==1,'travel2':travalMode==2,}"
								style="margin-right: 10px; float: right;padding:3px;border-radius: 3px;"
								@tap="changeTraval()">公交/地铁</view>
						</view>
					</view>
				</view>

				<view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13"
						style="align-items:center;width: 100%;border-bottom: 1px solid #e7e8e8;color: #AAAAAA;font-size: 13px;padding-bottom: 5px;">
						备注：5KM以内可选择公交/地铁，距离超出范围将默认为出租/滴滴。
					</view>
				</view>

				<view class="u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;">
							<view style="font-size: 28rpx;">预估出行车费</view>
						</view>
						<view style="width: 60%;text-align: right;color: #AAAAAA;">
							<view style="float: right;color: #FF5400;">
								{{travalMoney.bus===-1 && travalMoney.taxi===-1?'暂无':travalMode===1?travalMoney.bus:travalMoney.taxi}}
							</view>
						</view>
					</view>
				</view>

				<view class="u-p-t-10 u-p-b-15" style="color: #354F60;" @tap="chooseCoupon()">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="width: 40%;color: #333333;">
							<view style="font-size: 28rpx;">优惠券</view>
						</view>
						<view style="width: 60%;text-align: right;color: #AAAAAA;">
							<view style="float: right;color: #FF5400;">
								{{coupon.id?"满"+coupon.tiaoJian+"减"+coupon.price:"暂无可用优惠券"}} &gt;
							</view>
							<!-- 暂无可用优惠券 -->
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="cbg-white u-m-t-15">
			<view class="u-m-l-30 u-m-r-30">
				<view class="u-p-t-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="color: #333333;">
							<view style="font-size: 28rpx;">备注</view>
						</view>
					</view>
				</view>

				<view class="u-p-t-10 u-p-b-10" style="color: #354F60;">
					<u-input type="textarea" :fixed="true" :auto-height="true" maxlength="150" v-model="userInfo.remark"
						placeholder="如有特殊情况请提前告知（选填）"
						placeholder-style="font-size:14px;text-align: left;color:#AAAAAA" />
				</view>
			</view>
		</view>


		<view class="cbg-white u-m-t-15 u-p-b-15">
			<view class="u-m-l-30 u-m-r-30">
				<view class="u-p-t-15 u-p-b-15" style="color: #354F60;">
					<view class="cflex-r u-font-13" style="align-items:center;width: 100%;">
						<view class="cflex-r" style="color: #333333;font-size: 28rpx;">
							支付方式
						</view>
					</view>
				</view>

				<view>
					<u-radio-group active-color="red" style="display:flex;flex-direction: column;"
						v-model="userInfo.payMode.name">


						<u-radio class="cflex-r" name="pay_wx" style="width: 100%;" label-size="25rpx"
							@change="radioChange(1)">
							<view class="cflex-r" style="color: #333333;padding-left:10px;font-size: 28rpx;">
								<image style="height: 22px;width: 22px; margin-top: 4px;margin-right: 3px;"
									src="../../static/order/wx.png"></image>
								<view>微信支付</view>
							</view>
						</u-radio>
						<!-- <u-radio name="pay_amount" class="cflex-r" style="width: 100%;" label-size="25rpx"
							@change="radioChange(0)">
							<view class="cflex-r" style="color: #333333;padding-left:10px;">
								<image style="height: 22px;width: 22px; margin-top: 4px;margin-right: 3px;"
									src="../../static/order/zhanghu.png"></image>
								<view style="padding-top: 2px;font-size: 28rpx;">账户支付</view>
								<view style="padding-top: 2px;margin-left:10px;color: #AAAAAA;">
									({{userInfo.money ? userInfo.money:0 }})
								</view>
							</view>
						</u-radio> -->
						<!-- 	<view v-if="showWeiXin">
							<u-radio class="cflex-r" name="pay_zfb" style="width: 100%;" label-size="25rpx"
								@change="radioChange(2)">
								<view class="cflex-r" style="color: #333333;padding-left:10px;font-size: 28rpx;">
									<image style="height: 22px;width: 22px; margin-top: 4px;margin-right: 3px;"
										src="../../static/order/zfb.png"></image>
									<view>支付宝支付</view>
								</view>
							</u-radio>
						</view> -->

					</u-radio-group>
				</view>

			</view>
		</view>


		<view style="height: 150px;"></view>
		<view class="buy-cart">
			<view class="cflex-r" style="padding-top: 6px;width:50%;align-items: center;
			">
				<view>预计</view>
				<view style="color: #FF5400;font-size: 18px;" v-if="orderType != 'nanny_service'">
					￥ {{(userInfo.location.address===undefined || userInfo.location.address==='')?'0':allMoney}}
				</view>
				<view style="color: #FF5400;font-size: 18px;" v-else>
					￥ {{goodsObj.finalPrice*nannyMonth}}
				</view>
			</view>
			<view>
				<u-button type="default" shape="circle" @click="submitOrder()" :custom-style="buyBtn">立即下单</u-button>
			</view>
		</view>


		<u-select v-model="serveTpeShow" :list="columnsType" @confirm='confirmTye'
			@cancel='serveTpeShow=false'></u-select>

		<u-select v-model="DepartmentShow" :list="DepartmentList" @confirm='confirmTyeDepa'
			@cancel='DepartmentShow=false'></u-select>

		<u-select v-model="showNay" :list="columns" @confirm='confirm' @cancel='showNay=false'></u-select>

	</view>

</template>

<script>
	import store from "@/store/index.js"
	export default {
		data() {
			return {
				// #ifdef APP-PLUS
				showWeiXin: true,
				// #endif
				// #ifdef MP-WEIXIN
				showWeiXin: false,
				// #endif
				buyBtn: {
					backgroundColor: "#FF5400",
					fontSize: "17px",
					color: "white",
					border: "0px",
					height: "34px",
					'zIndex': 9
				},
				travalMode: 1, //出行方式
				travalMoney: {
					bus: -1,
					taxi: -1
				}, //出行费用
				option: {
					conpouId: 0
				}, //存储传递的参数
				jishiObj: {}, //计师对象
				goodsObj: {}, //项目对象
				//UserInfo:money(用户余额) payMode(支付方法:0[余额] 3[微信] 2[支付宝]) remark(备注) location(位置)
				//detailAddress表示详细地址  zuiZao表示最早可约时间，yuYueTime表示创建订单时上传的时间
				//Juli表示选择的地址和计师位置的距离
				userInfo: {
					name: "",
					phone: "",
					money: 0,
					payMode: {
						value: 1,
						name: "pay_wx"
					},
					remark: "",
					location: {},
					detailAddress: "",
					zuiZao: "",
					yuYueTime: "",
					Juli: ""
				},
				coupon: {},
				timeMood: null,
				qianNumber: 0,
				chuxing: 0,
				DepartmentId: '',
				DepartmentShow: false,
				DepartmentList: [],
				DepartmentName: '',
				hospitalList: [],
				columnsType: [

					{
						label: '病床护理',
						value: 1
					},
					{
						label: '社区护理',
						value: 2
					}

				],
				serveType: '',
				serveId: '',
				serveTpeShow: false,
				nannyMonth: 1,
				becareName: '',
				wid:'',
				bedNum: '',
				orderType: store.state.orderType,
				showNay: false,
				columns: [{
					label: '1个月',
					value: 1
				}, {
					label: '2个月',
					value: 2
				}, {
					label: '3个月',
					value: 3
				}, {
					label: '4个月',
					value: 4
				}, {
					label: '5个月',
					value: 5
				}, {
					label: '6个月',
					value: 6
				}, {
					label: '7个月',
					value: 7
				}, {
					label: '7个月',
					value: 7
				}, {
					label: '8个月',
					value: 8
				}, {
					label: '9个月',
					value: 9
				}, {
					label: '10个月',
					value: 10
				}, {
					label: '11个月',
					value: 11
				}, {
					label: '12个月',
					value: 12
				}],

			}
		},
		onShow() {
			this.getInfo();
			if (store.state.mood) {
				let number = []
				this.timeMood = store.state.mood
				this.timeMood = JSON.parse(JSON.stringify(store.state.mood))
				let timeMood = JSON.parse(JSON.stringify(this.timeMood))
				timeMood.forEach((item, i) => {
					item.timeList = item.timeList.filter(function(meth) {
						return meth.change
					});
					number.push(item.timeList.length)
				})


				console.log(this.timeMood, 3333333333)
				let sum = 0;
				for (let y = 0; y < number.length; y++) {
					sum += number[y];
				}
				this.qianNumber = sum

			}

			// let price = this.travalMode === 1 ? this.travalMoney.bus : this.travalMoney.taxi;
			// this.chuxing = price
		},
		onLoad(options) {
			this.option = JSON.parse(options.option);
			this.userInfo.zuiZao = this.option.zuiZao;
			this.orderType = store.state.orderType
			this.wid = options.wid
			this.httpRequest();
			// // //console.log(this.option);
			uni.$on("chooseCoupon", res => {
				if (res !== false) {
					this.coupon = res;
				} else {
					this.coupon = {};
				}

			});
			uni.$on("chooseTime", res => {
				setTimeout(() => {
					this.userInfo.zuiZao = res.starTime;
					this.userInfo.yuYueTime = res.startDate;
					this.$forceUpdate();
				}, 0)
				// // //console.log("Time", res)
			});
			this.hospital()
		},
		onUnload() {
			uni.$off("chooseCoupon");
			uni.$off("chooseTime");
		},
		computed: {

			allMoney() {
				let total = parseFloat(this.goodsObj.finalPrice);
				//项目加出行费用
				if (this.travalMoney.bus !== -1 || this.travalMoney.taxi !== -1) {
					let price = this.travalMode === 1 ? this.travalMoney.bus : this.travalMoney.taxi;
					total = total * this.qianNumber + parseFloat(price)
				}
				if (this.coupon.price) { //如果有优惠券
					total = total * this.qianNumber - parseFloat(this.coupon.price)
				}
				total = total.toFixed(2)
				return total;
			}
		},
		methods: {
			confirm(e) {
				console.log(e)
				this.nannyMonth = e[0].value
			},
			confirmTyeDepa(e) {
				this.DepartmentName = e[0].label
				this.DepartmentId = e[0].value
			},
			Department(e) {
				if (!this.serveType) {
					uni.showToast({
						title: '请先选择医院',
						icon: 'none'
					})
					return
				}
				this.DepartmentShow = true
			},
			confirmTye(e) {
				this.serveType = e[0].label
				this.serveId = e[0].value
				this.$request("kehu/hospital/department/list", {
					hid: this.serveId
				}).then(res => {
					if (res.rows) {
						let ress = res.rows
						this.DepartmentList = []
						ress.forEach((item, i) => {
							this.DepartmentList.push({
								label: item.name,
								value: item.hid
							})
						})

					}
				})
			},
			serveTpe() {
				this.serveTpeShow = true
			},
			hospital() {
				let type = 1
				if (store.state.orderType != 'hospital_care') {
					type = 2
				}
				this.$request("kehu/hospital/list", {
					type: type,
					toCity: uni.getStorageSync("address")
				}).then(res => {
					if (res.rows) {
						let ress = res.rows
						this.columnsType = []
						ress.forEach((item, i) => {
							this.columnsType.push({
								label: item.name,
								value: item.id
							})
						})

					}
					// 
				})
			},
			areAllEqual(arr) {
				return arr.every(element => element === arr[0]);
			},
			closetag(e, day) {
				let that = this
				let list = []
				this.timeMood.forEach((item, i) => {
					item.timeList.forEach((meth, k) => {
						if (item.day == day) {
							if (e.id == meth.id) {
								// this.timeMood[i].timeList.splice(k, 1)
								meth.change = ''
								meth.startTime = ''
								meth.endTime = ''
							}
							list.push(meth.startTime)
							that.timeMood[i].show = !that.areAllEqual(list)

						}
					})
				})
				this.timeMood.forEach((item, i) => {
					if (item.timeList.length === 0) {
						this.timeMood.splice(i, 1)
					}
				})

				this.$store.commit("setmood", this.timeMood);

				let timeMood = JSON.parse(JSON.stringify(this.timeMood))
				timeMood.forEach((item, i) => {
					item.timeList = item.timeList.filter(function(meth) {
						return meth.change
					});
				})

				let number = []
				timeMood.forEach((item, i) => {
					number.push(item.timeList.length)
				})

				let sum = 0;
				for (let y = 0; y < number.length; y++) {
					sum += number[y];
				}
				this.qianNumber = sum
				// let total = parseFloat(this.goodsObj.finalPrice);
				// let price = this.travalMode === 1 ? this.travalMoney.bus : this.travalMoney.taxi;
				// this.allMoney = total * this.qianNumber + parseFloat(price)
				console.log(this.timeMood)
			},
			getInfo() { //获得用户信息
				this.$request("kehu/user/info").then(res => {
					this.userInfo.name = res.data.name;
					this.userInfo.phone = res.data.phone;
					this.userInfo.money = res.data.money;
				})
			},
			phoneChange() {
				//console.log("c")
				setTimeout(() => {
					this.userInfo.phone = this.userInfo.phone.replace(/[^\d]/g, '')
				}, 0)

			},
			radioChange(index) { //支付方式更改
				this.userInfo.payMode.value = index;
				if (index === 0) {
					this.userInfo.payMode.name = "pay_amount"
				} else if (index === 1) {
					this.userInfo.payMode.name = "pay_wx"
				} else {
					this.userInfo.payMode.name = "pay_zfb"
				}
			},
			httpRequest() { //数据请求
				this.$request("kehu/jishi/detail", {
					wid: this.option.jishiId
				}).then(res => {
					this.jishiObj = res.data.worker;
				});
				this.$request("kehu/item/itemDetail", {
					id: this.option.goodsid,
					wId:this.wid
				}).then(res => {
					this.goodsObj = res.data;
					this.userInfo.totalMoney = this.goodsObj.finalPrice; //总费用(商品+出行-优惠券)
				});
			},
			getMoney() { //账号余额
				this.$request("kehu/other/qianBao").then(res => {
					// // //console.log(res);
					this.userInfo.money = res.data.yue;
				})
			},
			chooseCoupon() { //选择优惠券
				let total = parseFloat(this.goodsObj.finalPrice);
				//项目加出行费用
				if (this.travalMoney.bus !== -1 || this.travalMoney.taxi !== -1) {
					let price = this.travalMode === 1 ? this.travalMoney.bus : this.travalMoney.taxi;
					total = total + parseFloat(price);
				}
				// // //console.log("选择",this.goodsObj)
				uni.navigateTo({
					url: 'choose_coupou?price=' + total
				});
			},
			changeTraval() { //出行方式
				if (this.userInfo.Juli <= 5)
					this.travalMode = this.travalMode === 1 ? 2 : 1;
				else {
					uni.showToast({
						title: "5公里外只能为出租/滴滴",
						icon: "none"
					})
				}
			},
			chooseTime() { //选择服务时间
				// // //console.log("or", JSON.stringify(this.option))
				if (this.userInfo.location.address === undefined || this.userInfo.location.address === '') {
					uni.showToast({
						title: '请先选择服务地址',
						icon: 'none'
					})
					return
				}

				uni.navigateTo({
					url: 'service_time?option=' + JSON.stringify(this.option)
				});
			},
			checkOrder() { //对某些必要项进行检测
				if (this.userInfo.name.trim() === "") {
					uni.showToast({
						title: '请输入姓名',
						mask: true,
						icon: 'none'
					});
					return false;
				} else if (this.userInfo.phone.trim() === "") {
					uni.showToast({
						title: '请输入电话号码',
						mask: true,
						icon: 'none'
					});
					return false;
				} else if (!(/^\d*$/.test(this.userInfo.phone.trim()))) {
					uni.showToast({
						title: '电话号码只能为数字',
						mask: true,
						icon: 'none'
					});
					return false;
				} else if (this.userInfo.location.latitude === undefined) {
					uni.showToast({
						title: '请选择服务地址',
						mask: true,
						icon: 'none'
					});
					return false;
				} else if (this.userInfo.detailAddress.trim() === "") {
					uni.showToast({
						title: '请选择具体地址',
						mask: true,
						icon: 'none'
					});
					return false;
				} else if (!this.timeMood) {
					if (this.orderType != 'nanny_service') {
						uni.showToast({
							title: '请选择服务时间',
							mask: true,
							icon: 'none'
						});
						return false;
					}
				}
				// if (this.orderType == 'hospital_care') {
				// 	if (!this.serveId) {
				// 		uni.showToast({
				// 			title: '请选择医院',
				// 			mask: true,
				// 			icon: 'none'
				// 		});
				// 		return false;
				// 	} else if (!this.DepartmentId) {
				// 		uni.showToast({
				// 			title: '请选择科室',
				// 			mask: true,
				// 			icon: 'none'
				// 		});
				// 		return false;
				// 	} else if (!this.bedNum) {
				// 		uni.showToast({
				// 			title: '请输入床号',
				// 			mask: true,
				// 			icon: 'none'
				// 		});
				// 		return false;
				// 	} else if (!this.becareName) {
				// 		uni.showToast({
				// 			title: '请输入被护理人名称',
				// 			mask: true,
				// 			icon: 'none'
				// 		});
				// 		return false;
				// 	}
				// } 

				// if(this.orderType == 'home_service'){
				// 		if (!this.serveId) {
				// 			uni.showToast({
				// 				title: '请选择社区',
				// 				mask: true,
				// 				icon: 'none'
				// 			});
				// 			return false;
				// 		} else if (!this.becareName) {
				// 			uni.showToast({
				// 				title: '请输入被护理人名称',
				// 				mask: true,
				// 				icon: 'none'
				// 			});
				// 			return false;
				// 		}
				// 	}

				return true
			},
			submitOrder() { //订单创建
				// 
				//console.log("yu",this.userInfo.yuYueTime)
				let that = this
				if (this.checkOrder()) {
					let timeMood = ''
					if (this.orderType != 'nanny_service') {
						timeMood = JSON.parse(JSON.stringify(this.timeMood))
						timeMood.forEach((item, i) => {
							item.timeList = item.timeList.filter(function(meth) {
								return meth.change
							});
						})
						timeMood.forEach((item, i) => {
							if (item.timeList.length === 0) {
								timeMood.splice(i, 1)
							}
						})
						timeMood = JSON.parse(JSON.stringify(timeMood))
					}
					let loca = this.userInfo.location.address; //完整地址
					 // var str = "湖北省武汉市江夏区文化大道110号";
					 // var reg = /.+?(省|市|自治区|自治州|县|区)/g; // 省市区的正则
					 // console.log(str.match(reg));
					let cityName = loca.slice(loca.search("市") + 1, loca.search("区") + 1)
					let param = {
						wid: this.option.jishiId, //计师id
						iid: parseInt(this.option.goodsid), //项目id
						chuXing: this.travalMode - 1, //出行方式
						chuXingPrice: this.travalMode === 1 ? this.travalMoney.bus : this.travalMoney.taxi, //出行费用
						// yuYueTime: this.userInfo.yuYueTime, //预约时间
						yuYueTime: JSON.stringify(timeMood), //预约时间
						note: this.userInfo.remark || '', //备注
						address: this.userInfo.location.address, //定位大概地址
						addressDes: this.userInfo.detailAddress, //详细地址
						lat: this.userInfo.location.latitude, //经度
						lng: this.userInfo.location.longitude, //纬度
						payType: this.userInfo.payMode.value, //支付方式
						tel: this.userInfo.phone, //电话
						name: this.userInfo.name, //用户名
						typeCode: this.orderType,
						hid: this.serveId || '',
						hdid: this.DepartmentId || '',
						bedNum: this.bedNum || '',
						beCareName: this.becareName || '',
						nannyMonth: this.nannyMonth
					}
					param.cid = this.coupon.id === undefined ? 0 : this.coupon.id;

					//console.log(param);
					this.$request("kehu/order/createOrder", param).then(res => {
						//小程序支付
							var jsCode = uni.getStorageSync("jsCode");
							this.$request("pay/xiaoChengXuPay", {
								orderSn: res.data.orderSn,
								jsCode: jsCode
							}).then(res => {
								// #ifdef MP-WEIXIN
								wx.requestPayment({
									timeStamp: res.data.timeStamp,
									nonceStr: res.data.nonceStr,
									package: res.data.package,
									paySign: res.data.paySign,
									signType: res.data.signType,
									success(res) {
										uni.reLaunch({
											url: "../../pages/tab3"
										})
									},
									fail(err) {
										uni.showToast({
											title: '用户取消支付',
											icon: 'none',
											success() {
												uni.reLaunch({
													url: "../../pages/tab3"
												})
											}
										})
									}
								})
								// #endif

								// #ifdef H5
								if (that.$jwx && that.$jwx.isWechat()) { //检查是否是微信环境  	
									that.$jwx.wxpay({ //调用支付，
										'timestamp': res.data.timeStamp,
										'nonceStr': res.data.nonceStr,
										'package': res.data.package,
										'signType': res.data.signType,
										'paysign': res.data.paySign
									}, function(r) {
										if (r.errMsg == 'chooseWXPay:ok') {
											uni.reLaunch({
												url: "../../pages/tab3"
											})
										} else {
											that.$msg('支付失败！');
										}
									});

								}else{
									uni.showToast({
										title:'请在微信环境下运行',
										icon:'none'
									})
									return
								}
								// #endif
							})
							return
					});
				}
			},
			chooseLocation() { //选择服务地址
				//console.log("245");
				uni.chooseLocation({
					success: (res) => {
						console.log(res, 333)
						this.userInfo.location = res;
						this.userInfo.location.address = this.userInfo.location.address + this.userInfo
							.location.name;
						//console.log("1111===="+JSON.stringify(res))
						//获得出行费用
						this.$request("kehu/order/getChuZuMoney", {
							lat: res.latitude,
							lng: res.longitude,
							wid: this.jishiObj.id
						}).then(res => {
							console.log(res)
							this.travalMoney.bus = res.data.bus.toFixed(2);
							this.travalMoney.taxi = res.data.taxi.toFixed(2);
							this.userInfo.Juli = parseInt(res.data.juLi);
							//console.log("23",this.userInfo.Juli)
							setTimeout(() => { //判断距离和出行方式的关系
								this.travalMode = this.userInfo.Juli > 5 ? 3 : 1;
							}, 0)
						});
					},
					fail(err) {
						//console.log("失败");
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #F6F7F8;
	}

	/* 出行方式 1表示选中，2表示未选中*/
	.travel1 {
		color: #FF5400;
		border: 1px solid #FF5400;
	}

	.travel2 {
		color: #333333;
		border: 1px solid #999999;
	}

	.travel3 {
		/*不可选*/
		color: #999999;
		border: 1px solid #999999;
	}

	.buy-cart {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 15px 5% 20px 5%;
		background-color: white;
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 10;
	}
</style>